package com.nexmo.hangman.domain;


import javax.persistence.*;
import java.io.Serializable;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

@Entity
@Table(name = "game_state")
public class GameState implements Serializable{

    private static final String[] EXCLUDED_FIELDS = {"game"};

    @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "game"))
    @Id
    @GeneratedValue(generator = "generator")
    @Column(name = "game_id", unique = true, nullable = false)
    private Long gameId;

    //@MapsId
    @OneToOne
    @PrimaryKeyJoinColumn
    private Game game;

    @Column(name = "lives_remaining")
    private Integer livesRemaining;

    @Column(name = "introduced_letters")
    private String introduced;

    public Long getGameId() {
        return this.gameId;
    }

    public void setGameId(Long gameId) {
        this.gameId = gameId;
    }

    public Game getGame() {
        return game;
    }

    public void setGame(Game game) {
        this.game = game;
    }

    public Integer getLivesRemaining() {
        return livesRemaining;
    }

    public void setLivesRemaining(Integer livesRemaining) {
        this.livesRemaining = livesRemaining;
    }

    public String getIntroduced() {
        return introduced;
    }

    public void setIntroduced(String introduced) {
        this.introduced = introduced;
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj, EXCLUDED_FIELDS);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this, EXCLUDED_FIELDS);
    }
}
